package org.agile2soft.nexoma.core.tapestry.pages.profile;

import org.agile2soft.nexoma.core.CoreConstants;
import org.agile2soft.nexoma.core.entity.Profile;
import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.EventContext;
import org.apache.tapestry5.annotations.Component;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.beaneditor.BeanModel;
import org.apache.tapestry5.corelib.components.Zone;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.BeanModelSource;

import br.com.arsmachina.tapestrycrud.Constants;
import br.com.arsmachina.tapestrycrud.base.BaseListPage;

@SuppressWarnings("unused")
public class ListProfile extends BaseListPage<Profile,Integer> {

    @Inject
    private BeanModelSource beanModelSource;

    @Inject
    private Messages messages;

    @Override
    public BeanModel<Profile> getBeanModel() {
        BeanModel<Profile> beanModel = super.getBeanModel();
        beanModel.exclude("id");
        return beanModel;
    }

    @Component
    private Zone zone;



    @Override
    protected Object remove(Profile object) {
        if ( object.getInternalUsers().size()> 0 ) {
            //One ore more users has the profile assigned.
            // Set the warning message
            setMessage(messages.get(CoreConstants.MESSAGE_ERROR_PROFILE_WITH_USERS));
            return getFormZone();
        }
        return super.remove(object);
    }

}
